package com.augurit.gzcgwsp.ywcmn.web;

import java.util.List;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import com.augurit.common.base.action.BaseAction;
import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.gzcgwsp.ywcmn.service.IYwComClxxService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComClxxForm;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "yw-com-clxx.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/gzcgwsp/ywcmn/YwComClxx/YwComClxx.jsp"),
	@Result(name = CrudActionSupport.INPUT, location = "/gzcgwsp/ywcmn/YwComClxx/YwComClxx-input.jsp")
})
public class YwComClxxAction extends CrudActionSupport<YwComClxxForm>{

	@Autowired
	private IYwComClxxService ywComClxxService;

	private YwComClxxForm form;
	private Long id;
	private Long[] checkedIds;
	private Page<YwComClxxForm> page = new Page<YwComClxxForm>(10);


	/**
	 * ��ҳ��ѯ
	 */
	@Override
	public String list() throws Exception {
		ywComClxxService.search(page, form);
		return SUCCESS;
	}

	/**
	 * �������޸�
	 */
	@Override
	public String input() throws Exception {
		List<YwComClxxForm> clxxList = ywComClxxService.search(page, form).getResult();
		BaseAction.getRequest().setAttribute("clxxList", clxxList);
		System.out.println("form.getQymc() = "+form.getQymc());
		return INPUT;
	}
	
	/**
	 * �������޸�
	 */
	public String edit() throws Exception {
		if (id != null) {
			form = ywComClxxService.get(id);
		} else {
			form = new YwComClxxForm();
		}
		return INPUT;
	}

	/**
	 * �������������޸ĵ�Form����
	 */
	@Override
	public String save() throws Exception {
		ywComClxxService.save(form);
		return RELOAD;
	}

	/**
	 * ɾ��һ����¼
	 */
	@Override
	public String delete() throws Exception {
		ywComClxxService.delete(id);
		return RELOAD;
	}
	
	/**
	 * ɾ�������¼
	 */
	@Override
	public String deleteMore() throws Exception{
		ywComClxxService.delete(checkedIds);
		return RELOAD;
	}
	
	/**
	 * ׼��ҳ��ģ��
	 */
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			form = ywComClxxService.get(id);
		}
		else
			form = new YwComClxxForm();
	}
	

	public YwComClxxForm getModel() {
		return form;
	}
	
	// ����getter��setter����
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getCheckedIds() {
		return checkedIds;
	}

	public void setCheckedIds(Long[] checkedIds) {
		this.checkedIds = checkedIds;
	}
	
	public Page<YwComClxxForm> getPage() {
		return page;
	}


	public void setPage(Page<YwComClxxForm> page) {
		this.page = page;
	}
}
